package com.example.demo.mapper;


import com.example.demo.model.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("SELECT * FROM user WHERE user_id = #{userId}")
    User findUserById(Long userId);

    @Select("SELECT * FROM user WHERE username = #{username}")
        // 根据用户名查询用户（用于唯一性校验）
    User findByUsername(@Param("username") String username);

    @Insert("INSERT INTO user (username, password, role) VALUES (#{username}, #{password}, #{role})")
    int registerUser(User user);

    // 插入用户并返回影响的行数
    int insert(User user);


    // 检查用户名是否存在（返回布尔值）
    boolean existsByUsername(@Param("username") String username);

    @Select("SELECT * FROM user WHERE role = 'ADMIN'")
    List<User> findAllAdminUsers();


}

